Skip to content

Avoid redundant looping in property metadata - #29805

Merged
AndriySvyryd merged 1 commit into
mainfrom
Issue29642
Dec 16, 2022
Merged

Avoid redundant looping in property metadata#29805
AndriySvyryd merged 1 commit into
mainfrom
Issue29642

Conversation

@AndriySvyryd

Copy link
Copy Markdown
Member

Fixes #29642

@@ -858,29 +858,37 @@ private void Create(
var principalProperty = property;
for (var i = 0; i < 10000; i++)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 10,000 really the appropriate number here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be the length of the longest FK chain allowable in the model

@ajcvickers

Copy link
Copy Markdown
Contributor

Can you say a bit more about what is happening here? What are the situations where the 10,000 limit will be hit? Also, which tests cover these cases?

@roji roji changed the title Avoid reduntant looping in property metadata Avoid redundant looping in property metadata Dec 9, 2022
@AndriySvyryd

Copy link
Copy Markdown
Member Author

The code is traversing FKs. The 10000 limit will be hit if there's an FK cycle in the model. These models are invalid and will fail validation, but the current code runs before validation, so it shouldn't fail before validation runs.

Tests:

public virtual void Detects_relationship_cycle()

public virtual void Detects_shared_table_root_cycle()

@ajcvickers

ajcvickers commented Dec 12, 2022

Copy link
Copy Markdown
Contributor

The customer report didn't fail in validation. I get this was likely a bug, but it makes me nervous that we still have a very high limit such that some other bug could cause very slow model building without failing in validation. Should we not just fail early when we exhaust the loop, rather than assuming model validation will fail?

@AndriySvyryd

Copy link
Copy Markdown
Member Author

Should we not just fail early when we exhaust the loop, rather than assuming model validation will fail?

Sure, but only in main

@ajcvickers

Copy link
Copy Markdown
Contributor

Only in main seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance regression in model building in Entity Framework Core 7

2 participants